package com.bolt.auth.admin.api.quartz.dto.converter;


import com.bolt.auth.admin.api.quartz.dto.JobDTO;
import com.bolt.auth.admin.api.quartz.entity.JobEntity;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * Created by Administrator on 2018/11/27.
 */
public class JobConverter {
    private JobConverter() {
// do nothing
    }

    /**
     * Entity对象转换为DTO对象
     *
     * @param job DO对象
     * @return DTO对象
     */
    public static JobDTO toDTO(JobEntity job) {
        if (Objects.isNull(job)) {
            return null;
        }
        JobDTO result = new JobDTO();
        result.setId(job.getId());
        result.setBeanName(job.getBeanName());
        result.setCronExpression(job.getCronExpression());
        result.setIsPause(job.getIsPause());
        result.setJobName(job.getJobName());
        result.setMethodName(job.getMethodName());
        result.setParams(job.getParams());
        result.setDescription(job.getDescription());
        result.setPersonInCharge(job.getPersonInCharge());
        result.setEmail(job.getEmail());
        result.setSubTask(job.getSubTask());
        result.setPauseAfterFailure(job.getPauseAfterFailure());
        result.setCreateBy(job.getCreateBy());
        result.setUpdateBy(job.getUpdateBy());
        result.setCreateDate(job.getCreateDate());
        result.setUpdateDate(job.getUpdateDate());
        result.setVersionNO(job.getVersionNO());
        // TODO
        return result;
    }

    /**
     * DTO对象转换为Entity对象
     *
     * @param job DO对象
     * @return VO对象
     */
    public static JobEntity toEntity(JobDTO job) {
        if (Objects.isNull(job)) {
            return null;
        }
        JobEntity result = new JobEntity();
        result.setId(job.getId());
        result.setBeanName(job.getBeanName());
        result.setCronExpression(job.getCronExpression());
        result.setIsPause(job.getIsPause());
        result.setJobName(job.getJobName());
        result.setMethodName(job.getMethodName());
        result.setParams(job.getParams());
        result.setDescription(job.getDescription());
        result.setPersonInCharge(job.getPersonInCharge());
        result.setEmail(job.getEmail());
        result.setSubTask(job.getSubTask());
        result.setPauseAfterFailure(job.getPauseAfterFailure());
        result.setCreateBy(job.getCreateBy());
        result.setUpdateBy(job.getUpdateBy());
        result.setCreateDate(job.getCreateDate());
        result.setUpdateDate(job.getUpdateDate());
        result.setVersionNO(job.getVersionNO());
        // TODO
        return result;
    }

    /**
     * DTO对象转换为DO对象
     *
     * @param job DO对象
     * @return VO对象
     */
    public static JobEntity toEntity(JobEntity result, JobDTO job) {
        if (Objects.isNull(job)) {
            return null;
        }
        result.setBeanName(job.getBeanName());
        result.setCronExpression(job.getCronExpression());
        result.setIsPause(job.getIsPause());
        result.setJobName(job.getJobName());
        result.setMethodName(job.getMethodName());
        result.setParams(job.getParams());
        result.setDescription(job.getDescription());
        result.setPersonInCharge(job.getPersonInCharge());
        result.setEmail(job.getEmail());
        result.setSubTask(job.getSubTask());
        result.setPauseAfterFailure(job.getPauseAfterFailure());
        result.setCreateBy(job.getCreateBy());
        result.setUpdateBy(job.getUpdateBy());
        result.setCreateDate(job.getCreateDate());
        result.setUpdateDate(job.getUpdateDate());
// TODO
        return result;
    }

    /**
     * 批量 Entity对象转换为DTO对象
     *
     * @param jobList Entity集合对象
     * @return DTO对象
     */
    public static List <JobDTO> toDTO(List <JobEntity> jobList) {
        if (Objects.isNull(jobList)) {
            return null;
        }
        return jobList.stream().map(JobConverter::toDTO).collect(Collectors.toList());
    }

}
